jQuery.noConflict();

(function($){
	/*
	*@des: banner images fade
	*/
	function bannerFade(i){
		var arrItems = jQuery('#slider').find('a');
		var arrImgs = jQuery('#lstBanner').find('li');
		jQuery(arrItems[0]).addClass('active');
		
		var currentText = i;
		arrImgs.animate({'opacity': 0}, 1000);
		jQuery(arrImgs[i]).animate({'opacity': 1}, 1000);
		jQuery(arrItems).removeClass('active');
		jQuery(arrItems[i]).addClass('active');
		
		arrItems.each(function(index, item ){
			jQuery(item).bind('click', function(e){
				if(currentText == index) return false;
				 jQuery(arrImgs[currentText]).animate({'opacity': 0}, 1000);
				
					jQuery(arrImgs[index]).animate({'opacity': 1}, 1000);
					jQuery(arrItems[currentText]).removeClass('active');
					jQuery(arrItems[index]).addClass('active');
					currentText = index;
				
				return false;
			});
		});
	}
	
	var currentBanner = 0;
	function autoBanner(){
		if(jQuery('#lstBanner').find('li').length == -1){
			setInterval(function(){
				if(currentBanner > (jQuery('#lstBanner').find('li').length - 2)) {
					currentBanner = -1;
				}			
				currentBanner++;
				bannerFade(currentBanner);
			}, 500000 );
		}
	}
	/*
	*@des: slider images show
	*/
	
	function brandSlider(){
		var container = jQuery('#sliderBrand');
		if(container.length == 0) return;
		var prev = container.find('.btnSliderPrev');
		var next = container.find('.btnSliderNext');
		var slideObj = jQuery('#sliderBrand > div > ul');
		
		var arrImgs = jQuery('#sliderBrand > div > ul > li');
		
		
		var _WIDTH = 135;
		var _LENGTH = 7;
		var isClick = true;
		var currentIndex = 0;
		var currentText = 0;
		var _opacity = 0.2;
		prev.bind("click", function(evt) {
			showImage(currentImage - 1);
			return false;
		});
		
		next.bind("click", function(evt) {		
			showImage(currentImage + 1);
			return false;
		});
		
		var isMoving = false;
		var currentImage = 0;
		
		function imgFade(img, li){
			jQuery(img).animate({
				'opacity': 0
				},500, function(){
					isClick = true;
					jQuery(img).attr('src', jQuery(li).find('a').attr('href'));
					jQuery(img).load(function(){
						jQuery(img).animate({
							'opacity': 1
						}, 500);
					});
					
			});
			arrImgs.each(function(index, item ){
				jQuery(item).find('a').removeClass('active');
				jQuery(li).find('a').addClass('active');
			});
		}
		
		function showImage(index) {
			if (index < 0 || index >= arrImgs.length - (_LENGTH - 1)) {
				return;
			}
			
			if (isMoving) {
				return;
			}
			isMoving = true;
			
			currentImage = index;
			if (currentImage > 0) {
				prev.css({
					opacity: 1,
					cursor: 'pointer'
				});
			} else {
				prev.css({
					opacity: _opacity,
					cursor: 'default'
				});
			}
			
			if (currentImage <= arrImgs.length - (_LENGTH + 1)) {				
				next.css({
					opacity: 1,
					cursor: 'pointer'
				});
			} else {
				next.css({
					opacity: _opacity,
					cursor: 'default'
				});
			}
			
			slideObj.animate({
				"margin-left": -currentImage * _WIDTH
			}, 500, function(){
				isMoving = false;
			});
		}
		showImage(0);
		
	}
	/*
	*@des: restaurant Gallery slideshow
	*/
	function restaurantGallery(i){
		var arrItems = jQuery('#lstThumb').find('a');
		var arrImgs = jQuery('#lstVisual').find('li');
		jQuery(arrItems[0]).addClass('active');
		
		arrImgs.animate({'opacity': 0}, 1000);
		jQuery(arrImgs[i]).animate({'opacity': 1}, 1000);
		jQuery(arrItems).removeClass('active');
		jQuery(arrItems[i]).addClass('active');
		
		arrItems.each(function(index, item ){
			jQuery(item).bind('click', function(e){
				if(i == index)  return false;
				jQuery(arrImgs[i]).animate({'opacity': 0}, 1000);			
				jQuery(arrImgs[index]).animate({'opacity': 1}, 1000);
				jQuery(arrItems[i]).removeClass('active');
				jQuery(arrItems[index]).addClass('active');	
				i = index;
				return false;
			});
		});
	}
	jQuery(document).ready(function(){
		jQuery('#lstVisual').find('li').css('opacity', 0);
		setTimeout(function(){
			restaurantGallery(0);
		}, 1000);
		
		//bannerFade(0);
		//autoBanner();
		//brandSlider();
		jQuery('#lstBanner').cycle({
			fx:     'fade'
		});

	});
})(jQuery);
//////////////////////